package com.winning.cqs.pregnantbabycare_cqs_v1.table;

import java.io.Serializable;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;
import android.provider.BaseColumns;

import com.winning.cqs.pregnantbabycare_cqs_v1.utils.Constants;

public class Talk implements Serializable {

	private static final long serialVersionUID = 1L;

	public String talk_id;

	public String user_id;

	public String talk_content;

	public String talk_date;

	public String is_share = "0";

	public String share_title;

	public String share_image;

	public String share_url;

	public static void insertTalkToDb(ContentResolver cr, Talk talk) {
		if (null == cr || null == talk) {
			return;
		}

		ContentValues values = new ContentValues();

		values.put(TalkTable.CONTENT, talk.talk_content);
		values.put(TalkTable.DATE, talk.talk_date);
		values.put(TalkTable.USER_ID, talk.user_id);

		values.put(TalkTable.SHARE_TITLE, talk.share_title);
		values.put(TalkTable.SHARE_IMAGE, talk.share_image);
		values.put(TalkTable.SHARE_URL, talk.share_url);

		values.put(TalkTable.IS_SHARE, talk.is_share);

		if (values.size() > 0) {
			cr.insert(TalkTable.CONTENT_URI, values);

		}
	}

	// public static Talk getTalkByUserId(ContentResolver cr, String user_id) {
	// Talk talk = null;
	// if (null != cr) {
	// Cursor cursor = cr.query(TalkTable.CONTENT_URI, null,
	// TalkTable.USER_ID + "=" + user_id, null,
	// "date desc limit 10 ");
	// if (null != cursor && cursor.getCount() > 0) {
	// cursor.moveToFirst();
	// talk = new Talk();
	// talk.talk_id = cursor.getString(cursor
	// .getColumnIndex(TalkTable._ID));
	// talk.talk_content = cursor.getString(cursor
	// .getColumnIndex(TalkTable.CONTENT));
	// talk.talk_date = cursor.getString(cursor
	// .getColumnIndex(TalkTable.DATE));
	// talk.user_id = cursor.getString(cursor
	// .getColumnIndex(TalkTable.USER_ID));
	//
	// }
	// cursor.close();
	//
	// }
	// return talk;
	//
	// }

	// public static ArrayList<Talk> getTalkListByUserId(ContentResolver cr,
	// String user_id) {
	// ArrayList<Talk> talks = new ArrayList<Talk>();
	// if (null != cr) {
	// Cursor cursor = cr.query(TalkTable.CONTENT_URI, null,
	// TalkTable.USER_ID + "=" + user_id, null, " date desc  ");
	// if (null != cursor && cursor.getCount() > 0) {
	// int talkCount = cursor.getCount();
	// cursor.moveToFirst();
	// for (int k = 0; k < talkCount; k++) {
	// Talk talk = new Talk();
	// talk.talk_id = cursor.getString(cursor
	// .getColumnIndex(TalkTable._ID));
	// talk.talk_content = cursor.getString(cursor
	// .getColumnIndex(TalkTable.CONTENT));
	// talk.talk_date = cursor.getString(cursor
	// .getColumnIndex(TalkTable.DATE));
	// talk.user_id = cursor.getString(cursor
	// .getColumnIndex(TalkTable.USER_ID));
	// talks.add(talk);
	// cursor.moveToNext();
	// }
	// }
	// cursor.close();
	//
	// }
	// return talks;
	//
	// }

	// public static ArrayList<Talk> getTalkList(ContentResolver cr, int
	// offset_num) {
	// ArrayList<Talk> talks = null;
	// if (null != cr) {
	// Cursor cursor = cr.query(TalkTable.CONTENT_URI, null, null, null,
	// "date desc limit " + (20 * (++offset_num)) + "  offset  "
	// + (offset_num * 15));
	// if (null != cursor && cursor.getCount() > 0) {
	// int talkCount = cursor.getCount();
	// cursor.moveToFirst();
	// talks = new ArrayList<Talk>();
	// for (int k = 0; k < talkCount; k++) {
	// Talk talk = new Talk();
	// talk.talk_id = cursor.getString(cursor
	// .getColumnIndex(TalkTable._ID));
	// talk.talk_content = cursor.getString(cursor
	// .getColumnIndex(TalkTable.CONTENT));
	// talk.talk_date = cursor.getString(cursor
	// .getColumnIndex(TalkTable.DATE));
	// talk.user_id = cursor.getString(cursor
	// .getColumnIndex(TalkTable.USER_ID));
	// talks.add(talk);
	// cursor.moveToNext();
	// }
	// }
	// cursor.close();
	//
	// }
	// return talks;
	//
	// }

	public static class TalkTable implements BaseColumns {

		public static final String TABLE_NAME = "talk";

		public static final Uri CONTENT_URI = Uri.parse("content://"
				+ Constants.AUTHORITY + "/" + TABLE_NAME);

		public static final String CONTENT_TYPE = "vnd.android.cursor.dir/"
				+ Constants.AUTHORITY + "/" + TABLE_NAME;

		public static final String USER_ID = "user_id";

		public static final int USER_ID_INDEX = 1;

		public static final String CONTENT = "content";

		public static final int CONTENT_INDEX = 2;

		public static final String IS_SHARE = "is_share";

		public static final int IS_SHARE_INDEX = 3;

		public static final String SHARE_IMAGE = "share_image";

		public static final int SHARE_IMAGE_INDEX = 4;

		public static final String SHARE_TITLE = "share_title";

		public static final int SHARE_TITLE_INDEX = 5;

		public static final String SHARE_URL = "share_url";

		public static final int SHARE_URL_INDEX = 6;

		public static final String DATE = "date";

		public static final int DATE_INDEX = 7;

		public static final String TABLE_CREATESQL = "CREATE TABLE "
				+ TABLE_NAME + " (" + "_id"
				+ " INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," + USER_ID
				+ " TEXT," + CONTENT + " TEXT," + IS_SHARE + " TEXT,"
				+ SHARE_IMAGE + " TEXT," + SHARE_TITLE + " TEXT," + SHARE_URL
				+ " TEXT," + DATE + " TEXT" + ");";

	}

}
